package com.jxz.vip.web.handle;

import com.jxz.vip.entity.UserEntity;
import com.jxz.vip.function.UserFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by 金贤哲 on 2017/3/28 0028.
 */
@Controller
public class LoginHandle {
    @Autowired
    UserFunction fun;
    @RequestMapping("/Login.do")
    public String Login(String account, String password, HttpServletRequest request){
        try {
            UserEntity u =fun.login(account,password);
            HttpSession session = request.getSession();
            session.setAttribute("currentUser",u);
        }catch (Exception e){
            request.setAttribute("message",e.getMessage());
           return "forward:/Login.jsp";
        }

          return "redirect:/index.do";
    }
    @RequestMapping("/index.do")
    public String index(){
        return "index";
    }
}
